const Koa = require('koa');
const Router = require('koa-router');

const app = new Koa();
const router = new Router();


// 引入服务器里面的数据
const indexData  = require('./datas/index.json')
const categoryData = require('./datas/categoryDatas.json')

// 配置路由
router.get('/', (ctx, next) => {
  ctx.body = {
		code:200,
		person:{
			name:'小甜甜',
			age:18
		}
	}
});
// 配置路由
router.get('/indexData',(ctx,next)=>{
	ctx.body = {
		code:200,
		indexData
	}
})

router.get('/categoryData',(ctx,next)=>{
	ctx.body = {
		code:200,
		categoryData
	}
})

app
  .use(router.routes())
  .use(router.allowedMethods());
	
	
	// 监听端口
	app.listen(3000,(err)=>{
		if(err){
			console.log('服务器启动失败',err)
		}else{
			console.log('服务器启动成功,3000端口监听中')
		}
	});